#define _CRT_SECURE_NO_WARNINGS 1


struct ListNode {
    int val;
    ListNode* next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode* pcur = head;
        ListNode* prev = nullptr;
        while (pcur != nullptr && pcur->next != nullptr)
        {
            prev = pcur;
            pcur = pcur->next;
            if (pcur->val == prev->val)
            {
                prev->next = pcur->next;
                delete pcur;
                pcur = prev;
            }
        }
        return head;
    }
};